<?php

namespace App\Http\Controllers\Erp;

use App\CodeResponse;
use App\Repositories\Basic\MachineRepository;
use App\Repositories\Basic\ShopRepository;
use Illuminate\Http\Request;

class MachineController extends ErpController
{

    protected $machineRepository;

    public function __construct(MachineRepository $machineRepository)
    {
        $this->machineRepository = $machineRepository;

    }

    public function list(Request $request)
    {
        $input = $request->input();

        if(empty($input['is_all'])){
            $list = $this->machineRepository->getList();
            return $this->paginate($list);
        }else{
            $list = $this->machineRepository->getAll();
            return $this->success($list);
        }
    }

    public function detail($id)
    {
        $data = $this->machineRepository->getById($id);
        return $this->success($data);

    }

    public function create(Request $request)
    {
        $params = $request->input();
        $flag = $this->machineRepository->create($params);
        return $this->failOrSuccess($flag, CodeResponse::CREATED_FAIL, $flag);

    }

    public function update($id, Request $request)
    {
        $params = $request->input();
        $flag = $this->machineRepository->update($id, $params);
        return $this->failOrSuccess($flag, CodeResponse::UPDATED_FAIL, $flag);

    }


}